from pymongo import MongoClient
def get_mongo_url(username,password,ip,port,dbname):
    mongo_uri = f"mongodb://{username}:{password}@{ip}:{port}/{dbname}?authSource=admin"
    return mongo_uri

def new_client(url, db, coll):
    """
    创建一个新连接
    :param url: 
    :param db: 
    :param coll: 
    :return: 
    """
    return MongoClient(url)[db][coll]

def download_collection(url,dbname, colllection , query_dict):
    """
    下载一整个collection
    :param url: 
    :param dbname: 
    :param colllection: 
    :param query_dict: 
    :return: 
    """
    res = []
    collection_ob =  new_client(url, dbname,colllection)
    for x in collection_ob.find(query_dict):
        res.append(x)
    return res 